package com.fc.advbox.controller.api;

import com.fc.advbox.common.ResponseJson;
import com.fc.advbox.controller.admin.BaseController;
import com.fc.advbox.dto.equipment.QueryEquipmentRequest;
import com.fc.advbox.dto.user.UserPointDto;
import com.fc.advbox.entity.EquipmentEntity;
import com.fc.advbox.entity.UserPointEntity;
import com.fc.advbox.service.IEquipmentService;
import com.fc.advbox.service.IUserPointService;
import com.fc.advbox.utils.Constant;
import com.fc.advbox.utils.RRException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by E7450 on 2018/6/27.
 */
@RestController
@RequestMapping("/api/user/point")
@Api(value="用户积分接口", tags={"用户积分接口"})
public class UserPointController extends BaseController {

    @Autowired
    private IUserPointService userPointService;

    @ApiOperation(value = "POST -- 查询积分列表",
            notes = " REST 方式请求" +
                    "Request Body: <ul>" +
                    "<li><i>必填参数: userId: 用户ID</i></li>" +
                    "<li><i>默认参数: page: 1, 当前页，默认值1 </i></li>" +
                    "<li><i>默认参数: limit: 每次查询个数，默认为20</i></li>" +
                    "</ul>")
    @PostMapping("/list")
    public ResponseJson doQueryList(@RequestBody Map<String, Object> params) {
        //校对并赋值 offset和limit
        calculatePagination(params);

        List<UserPointEntity> pointList = userPointService.queryList(params);
        return ResponseJson.success(pointList);
    }

    @ApiOperation(value = "GET -- 查看单个历史积分信息",
            notes = " REST 方式请求" +
                    "/info/{pointHistoryId}")
    @GetMapping("/info/{pointHistoryId}")
    public ResponseJson doQueryInfo(@PathVariable("pointHistoryId") Long pointHistoryId) {

        if(pointHistoryId == null || pointHistoryId == 0)
        {
            throw new RRException("ID不能为空!");
        }

        UserPointEntity pointHistory = userPointService.queryObject(pointHistoryId);
        return ResponseJson.success(pointHistory);
    }
}
